package org.smileface.designpattern.singleton;

/**
 * @description: 单例模式-枚举类方式（懒汉式）
 * @author: chujian
 * @since: 2022-02-14 09:40
 **/
public class Singleton4 {
    private Singleton4() {
    }

    public static Singleton4 getInstance() {
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton {
        INSTANCE;
        private final Singleton4 singleton;

        // JVM 保证这个方法只被调用一次
        Singleton() {
            singleton = new Singleton4();
        }

        public Singleton4 getInstance() {
            return singleton;
        }
    }
}
